package cc.zy.base.businesses.controller;

import cc.zy.base.businesses.entity.College;
import cc.zy.base.businesses.service.ICollegeService;
import cc.zy.base.businesses.service.IStudentService;
import cc.zy.base.common.controller.BaseController;
import cc.zy.base.common.entity.FebsConstant;
import cc.zy.base.common.utils.DateUtil;
import cc.zy.base.common.utils.FebsUtil;
import cc.zy.base.hr.entity.StaffLabel;
import cc.zy.base.hr.service.IStaffLabelService;
import cc.zy.base.system.entity.User;
import cc.zy.base.system.service.IUserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * @author Jiangjinlin
 */
@Slf4j
@Controller("businessesView")
@RequiredArgsConstructor
public class ViewController extends BaseController {

    private final ICollegeService collegeService;
    private final IStudentService studentsService;
    private final IStaffLabelService staffLabelService;


    @GetMapping(FebsConstant.VIEW_PREFIX + "college/list")
    public String college() {
        return FebsUtil.businessesView("college/college");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "college/detail/{id}")
    public String collegeDetail(@PathVariable Integer id, Model model) {
        resolveCollegeModel(id, model, true);
        return FebsUtil.businessesView("college/collegeDetail");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "college/update/{id}")
    public String collegeUpdate(@PathVariable Integer id, Model model) {
        resolveCollegeModel(id, model, false);
        return FebsUtil.businessesView("college/collegeUpdate");
    }
    @GetMapping(FebsConstant.VIEW_PREFIX + "college/add")
    public String collegeAdd() {
        return FebsUtil.businessesView("college/collegeAdd");
    }

    /**
     * 裴子鉴结束
     */
    private void resolveCollegeModel(Integer id, Model model, Boolean transform) {
        College college = collegeService.findById(id);
        if (college.getCreateDate() != null) {
            model.addAttribute("createDateTime", DateUtil.getDateFormat(college.getCreateDate(), DateUtil.FULL_TIME_SPLIT_PATTERN));
        }
        if (college.getUpdateDate() != null) {
            model.addAttribute("updateDateTime", DateUtil.getDateFormat(college.getUpdateDate(), DateUtil.FULL_TIME_SPLIT_PATTERN));
        }
        model.addAttribute("college", college);
    }

    /**
     * 张志钊开始
     **/
    private final IUserService userService;

    //跳转selectStudent页面
    @GetMapping(FebsConstant.VIEW_PREFIX + "student/list")
    public String student() {
        return FebsUtil.businessesView("students/selectStudent");
    }

    //跳转到noticeAdd页面
    @GetMapping(FebsConstant.VIEW_PREFIX + "notice/add")
    public String noticeAdd(Model model) {
        User principal = userService.findByName(getCurrentUser().getUsername());
        model.addAttribute("username", principal.getUsername());//传递到noticeAdd页面
        model.addAttribute("userId", principal.getUserId());//传递到noticeAdd页面
        return FebsUtil.businessesView("notice/noticeAdd");
    }
    /**张志钊结束**/



    /**
     * 跳转通知列表页面
     *
     * @return
     */
    @GetMapping(FebsConstant.VIEW_PREFIX + "businesses/Notice")
    public String Notice() {
        return FebsUtil.businessesView("notice/notice");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "networkSchool/view")
    public String goNetworkSchool() {

        return FebsUtil.businessesView("networkSchool/networkSchool");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "entranceScore/errorResult")
    public String getErrorLog() {

        return FebsUtil.businessesView("score/entranceExportResult");
    }

}